"""
面向对象编程
"""

# 定义类


class Student:
    pass


# 类的实例
s = Student()
print(s)
s.name = 'Michael'
print(s.name)

# 构造函数和类方法


class Student2:
    # 构造函数，第一个参数永远是self，表示创建的实例本身
    def __init__(self, name, age):
        self.name = name
        self.age = age

    # 打印分数
    def print_score(self):
        print('%s: %s' % (self.name, self.age))


s2 = Student2('Michael', 25)
print(s2.name)
s2.print_score()

# 访问限制


class Student3:
    # 构造函数，第一个参数永远是self，表示创建的实例本身
    def __init__(self, name, age):
        self.__name = name
        self.__age = age

    # 打印分数
    def print_score(self):
        print('%s: %s' % (self.__name, self.__age))

    # 访问限制
    def get_age(self):
        return self.__age


s3 = Student3('Michael', 25)
print(s3.get_age())


# 继承和多态
class Animal:
    def run(self):
        print('Animal is running...')


class Dog(Animal):
    def run(self):
        print('Dog is running...')


class Cat(Animal):
    def run(self):
        print('Cat is running...')


def run_twice(animal):
    animal.run()


run_twice(Animal())
run_twice(Dog())

# 判断对象类型
print(isinstance(Animal(), Animal))
print(type(Dog()))

# 获取对象信息
print(dir(Animal()))

# 类属性
class Student4:
    # 类属性
    count = 0
    def __init__(self, name, age):
        self.name = name
        self.age = age  

